package com.pengshun.modules.api.user.controller;

import com.pengshun.modules.api.coal.validator.*;
import com.pengshun.modules.api.user.para.CarPara;
import com.pengshun.modules.api.user.service.UserDriverService;
import com.pengshun.modules.api.user.service.dto.CarDrivingDto;
import com.pengshun.modules.api.user.service.dto.OwnerDrivingDto;
import com.pengshun.modules.api.user.service.dto.UserDriverDto;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.domain.OwnerDriving;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequiredArgsConstructor
@Api(tags = "司机管理")
@RequestMapping("/api/driver")
@ApiIgnore
public class UserDriverController {


    private final UserDriverService userDriverService;

    @ApiOperation(value = "司机列表", notes = "待确认、未通过 列表 按钮是否显示isShow (0不显示,1显示)/n 显示文字：showContent ")
    @GetMapping(value = "/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
            @ApiImplicitParam(name = "status", value = "类型(0:待确认，1已通过，2未通过,3已解绑,)", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "请求条数", dataType = "int", required = true, paramType = "query"),

    })
    @Authorization
    public BaseResult detil(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) CarPara para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = userDriverService.list(para);
        return res;
    }

    @ApiOperation(value = "关联车主/司机", notes = "  ")
    @PostMapping(value = "/inners")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
            @ApiImplicitParam(name = "carUserId", value = "传电话查询用的userId", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "type", value = "1司机发起,2车主发起", dataType = "int", required = true, paramType = "query"),

    })
    @Authorization
    public BaseResult inners(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) OwnerDrivingDto para) throws Exception {
        para.setDrivingUserId(user.getId());
        BaseResult res = userDriverService.inners(para);
        return res;
    }

    @ApiOperation(value = "给司机 添加车辆/修改关联车辆", notes = " ")
    @PostMapping(value = "/save")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
            @ApiImplicitParam(name = "ownerDrivingId", value = "车主司机id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "carOwnerId", value = "车辆id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "drivingUserId", value = "司机id", dataType = "int", required = true, paramType = "query"),
    })
    @Authorization
    public BaseResult save(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Second.class}) CarDrivingDto para) throws Exception {
        para.setCarUserId(user.getId());
        BaseResult res = userDriverService.save(para);
        return res;
    }

    @ApiOperation(value = "解绑", notes = " ")
    @PostMapping(value = "/unbundling")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
            @ApiImplicitParam(name = "ownerDrivingId", value = "车主司机id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = "类型(0:待关联，1同意，2拒绝，3解绑)", dataType = "int", required = true, paramType = "query"),
    })
    @Authorization
    public BaseResult unbundling(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Sixth.class}) CarDrivingDto para) throws Exception {
        para.setDrivingUserId(user.getId());
        BaseResult res = userDriverService.unbundling(para);
        return res;
    }

    @ApiOperation(value = "冻结  解冻", notes = " ")
    @PostMapping(value = "/freeze")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
            @ApiImplicitParam(name = "carDrivingId", value = "车主司机关联id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = "0冻结 1解冻", dataType = "int", required = true, paramType = "query"),
    })
    @Authorization
    public BaseResult freeze(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Fourth.class}) CarDrivingDto para) throws Exception {
        para.setDrivingUserId(user.getId());
        BaseResult res = userDriverService.freeze(para);
        return res;
    }

    @ApiOperation(value = "查询司机关联车辆表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ownerDrivingId", value = "车主司机id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "1 已关联 2未关联", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/car-list")
    @Authorization
    public BaseResult carList(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) UserDriverDto para) throws Exception {
        para.setCarUserId(user.getId());
        BaseResult res = userDriverService.notBindingCarList(para);
        return res;
    }

}
